/****************************************************************************************
Implementation Name: List.cpp
Des:  This file contains the function definitions declared in the List.
Author: Alberto De Pena
Due Date: 10/14/2009 @ 11:55 pm
****************************************************************************************/
#include <iostream>
#include "List.h"

using namespace std;

//Constructor
List::List()
{}
//function needed to calculate the amount of grade entered
int List::ListCount()
{
	int nodeCount = 0;
	for(Node* i = Head; i != NULL; i = i -> Next)
		nodeCount++;

	return nodeCount;
}	
//function needed to calculate the mean of grade entered
ListType List::ListMean()
{
	return(ListSum())/ListCount();
}	
//function needed to calculate the highest grade entered
ListType List::ListHigh()
{
	ListType High = Head -> data;
	for(Node* i = Head; i != NULL; i = i -> Next)
		if(High < i -> data)
			High = i -> data;

	return High;
}	
//function needed to calculate the lowest grade entered
ListType List::ListLow()
{
	ListType Low = Head -> data;
	for(Node* i = Head; i != NULL; i = i -> Next)
		if(Low > i -> data)
			Low = i -> data;

	return Low;
}	
//function needed to calculate the sum of the grades entered
ListType List::ListSum()
{
	ListType Sum = 0;
	for(Node* i = Head; i != NULL; i = i -> Next)
		Sum = Sum + i -> data;

	return Sum;
} 
//function needed to add all of the grades entered
bool List::ListAdd(ListType Grade)
{
	Node* P = new Node;
	if(P == NULL)
		return false;
	
	P -> data = Grade;
	P -> Next = NULL;

	if(Head == NULL)
		Head = P;
	else
	{
		Node* Curr;
		for(Curr = Head; Curr -> Next != NULL; Curr = Curr -> Next);
			Curr -> Next = P;
	}
	return true;
}
//function needed to calculate the range of the grades entered
int List::ListRange(ListType High_Grade, ListType Low_Grade)
{
	int countRange = 0;
	for(Node* i = Head; i != NULL; i = i -> Next)
	{
		if(i -> data <= High_Grade && i -> data >= Low_Grade)
			countRange++;
	}
	return countRange;
}
//Destructor
List::~List()
{
	Node* tmp;
	while(Head != NULL)
	{
		tmp = Head;
		Head = Head -> Next;
		delete tmp;
	}
}
